package com.fsc.controller;

import com.fsc.entity.ResultWrapper;
import com.fsc.entity.domain.SchoolInfo;
import com.fsc.entity.dto.SchoolDTO;
import com.fsc.entity.vo.SchoolVO;
import com.fsc.service.SchoolInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.fsc._enum.ReturnEnum.SUCCESS;

@RestController
@RequestMapping("/school/")
public class SchoolController {
    @Autowired
    private SchoolInfoService schoolInfoService;

    @PostMapping("add")
    public ResultWrapper<String> addSchool(@RequestBody SchoolDTO schoolDTO){
        SchoolInfo schoolInfo = SchoolInfo.builder()
                .schoolId(schoolDTO.getSchoolId())
                .schoolName(schoolDTO.getSchoolName())
                .profile(schoolDTO.getProfile())
                .level(schoolDTO.getLevel())
                .build();
        schoolInfoService.save(schoolInfo);
        return ResultWrapper.success(SUCCESS);
    }

    @PostMapping("{schoolId}")
    public ResultWrapper<SchoolVO> getSchool(@PathVariable Integer schoolId){
        return schoolInfoService.selectById(schoolId);
    }
}
